//
//  MBQRCodeView.m
//  MemberBusiness-ios
//
//  Created by 掌心 on 2018/5/31.
//  Copyright © 2018年 zhangXin. All rights reserved.
//

#import "MBQRCodeBgView.h"
#import "MBTopCenterButton.h"

@interface MBQRCodeBgView ()
@property (nonatomic,weak)UIImageView * qrImage;

@property (nonatomic,strong)NSTimer   *time;
@end

@implementation MBQRCodeBgView

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor clearColor];
        self.opaque = NO; // 设置为透明的
        UIImageView * qrImage = [[UIImageView alloc]initWithFrame:CGRectMake([UIView lf_sizeFromIphone6:56], [UIView lf_sizeFromIphone6:102], SCREEN_WIDTH-[UIView lf_sizeFromIphone6:112], SCREEN_WIDTH-[UIView lf_sizeFromIphone6:112])];
        qrImage.image = [UIImage imageNamed:@"qrjiao"];
        self.qrImage = qrImage;
        [self addSubview:qrImage];
        UIImageView *lineImage = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, [UIView lf_sizeFromIphone6:264], [UIView lf_sizeFromIphone6:5])];
        lineImage.image = [UIImage imageNamed:@"qr_line"];
        lineImage.contentMode = UIViewContentModeScaleAspectFit;
        [self.qrImage addSubview:lineImage];
        CABasicAnimation * theAnimation;
        theAnimation = [CABasicAnimation animationWithKeyPath:@"transform.translation.y"];
        //        theAnimation.delegate= self;
        theAnimation.duration = 2.5;
        theAnimation.repeatCount = MAXFLOAT;
        theAnimation.removedOnCompletion = FALSE;
        theAnimation.fillMode = kCAFillModeForwards;
        theAnimation.autoreverses = YES;
        theAnimation.fromValue = [NSNumber numberWithFloat:0];
        theAnimation.toValue = [NSNumber numberWithFloat:qrImage.height];
        [lineImage.layer addAnimation:theAnimation forKey:@"lineAnimation"];
        
        UILabel* messageLabel = [[UILabel alloc]init];
        messageLabel.text = @"将二维码放入框内，即可自动扫描";
        messageLabel.font = [UIFont lf_systemFontOfSize:13];
        messageLabel.textColor = [UIColor colorWithR:120 G:120 B:120];
        [self addSubview:messageLabel];
        
        [messageLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(qrImage.mas_bottom).offset([UIView lf_sizeFromIphone6:15]);
            make.centerX.equalTo(self);
        }];
        
        UIView* shadowView = [[UIView alloc]init];
        shadowView.backgroundColor = [UIColor colorWithR:46 G:46 B:46 A:0.7];
        [self addSubview:shadowView];
        
        [shadowView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.left.right.equalTo(self);
            make.height.mas_equalTo([UIView lf_sizeFromIphone6:80]);
        }];
        
        MBTopCenterButton* scanButton = [[MBTopCenterButton alloc]init];
        self.scanButton = scanButton;
        [scanButton setImage:[UIImage imageNamed:@"scan"] forState:UIControlStateNormal];
        [scanButton setTitle:@"扫码" forState:UIControlStateNormal];
        [scanButton setTitleColor:[UIColor colorWithR:255 G:99 B:0] forState:UIControlStateNormal];
        scanButton.titleLabel.font = [UIFont lf_systemFontOfSize:12];
        [shadowView addSubview:scanButton];
        
        [scanButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(shadowView);
            make.left.equalTo(shadowView).offset([UIView lf_sizeFromIphone6:83]);
            make.size.mas_equalTo(CGSizeMake([UIView lf_sizeFromIphone6:25], [UIView lf_sizeFromIphone6:41]));
        }];
        
        MBTopCenterButton* photoButton = [[MBTopCenterButton alloc]init];
        self.photoButton = photoButton;
        [photoButton setImage:[UIImage imageNamed:@"photo"] forState:UIControlStateNormal];
        [photoButton setTitle:@"相册" forState:UIControlStateNormal];
        photoButton.titleLabel.font = [UIFont lf_systemFontOfSize:12];
        [shadowView addSubview:photoButton];
        
        [photoButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(shadowView);
            make.right.equalTo(shadowView).offset([UIView lf_sizeFromIphone6:-83]);
            make.size.mas_equalTo(CGSizeMake([UIView lf_sizeFromIphone6:25], [UIView lf_sizeFromIphone6:41]));
        }];
    }
    return self;
}


@end
